package example.proxy.cglib;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class MeiPo implements MethodInterceptor {

    public Object getInstance(Class object) throws Exception {
        // 通过反射机制
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(object);
        enhancer.setCallback(this);
        return enhancer.create();
    }

    @Override
    public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        System.out.println("我是媒婆，我要开始给你介绍对象了");
        System.out.println("开始物色人选------");

        methodProxy.invokeSuper(object, args);

        System.out.println("相亲完毕------");
        System.out.println("合适就准备办事吧");
        return null;
    }
}
